package com.example.yk_fx.live;

import android.os.Handler;
import android.view.View;

import com.example.yk_fx.entity.GiftEntity;

import java.util.Timer;
import java.util.TimerTask;

public class GiftControl {
    private GiftView giftView;
    Timer timer;
    Handler handler = new Handler(){};
    long lastTime;
    int count = 0;

    public GiftControl(GiftView giftView) {
        this.giftView = giftView;
        timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                if(System.currentTimeMillis()-lastTime>3000){
                    //重新开始计数
                    count = 0;
                    //暴击效果隐藏
                    handler.post(new Runnable() {
                        @Override
                        public void run() {
                            giftView.setVisibility(View.GONE);
                        }
                    });
                }
            }
        },0,100);
    }

    public void giftShow(GiftEntity.DataBean gift){
        if(count==0){
            giftView.setVisibility(View.VISIBLE);
            count++;
            lastTime = System.currentTimeMillis();
        }else if(System.currentTimeMillis()-lastTime<2000){
            count++;
            lastTime = System.currentTimeMillis();
        }
        giftView.loadUser("123");
        giftView.loadGift(gift);
        giftView.loadCount(count);
    }
}
